package com.example.mall.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.Assert;

import java.util.Arrays;

@AllArgsConstructor
@Getter
public enum ModuleEnum {

    COMMON("common", "公共模块"),
    COUPON("coupon", "优惠券模块"),
    MEMBER("member", "会员模块"),
    ORDER("order", "订单模块"),
    PRODUCT("product", "产品模块"),
    WARE("ware", "库存模块"),
    EMPTY("", "EMPTY"),
    ;

    /** 模块编码 */
    private final String code;

    /** 模块名称 */
    private final String name;

    public static String getModuleCodeIfContains(String str) {
        Assert.notNull(str, "字符串不能为空");
        return Arrays.stream(values())
                .filter(moduleEnum -> str.contains(moduleEnum.code))
                .findFirst().orElse(EMPTY).getCode();
    }

}
